package com.dd.census.service.impl;

import com.dd.census.entity.Resume;
import com.dd.census.mapper.ResumeMapper;
import com.dd.census.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;

/**
 * 业务层实现类
 * Staff1ServiceImpl
 * @author whn
 * @date 2020/11/26
 */
@Service
public class ResumeServiceImpl implements ResumeService {

    @Autowired
	ResumeMapper resumeMapper;

    @Override
    public int insertResume(Resume resume) {
        return resumeMapper.insertResume(resume);
    }

    @Override
    public int updateResume(Resume resume) {
    	return resumeMapper.updateResume(resume);
    }

	@Override
	public Resume selectResumeByKey(String id) {
		return resumeMapper.selectResumeByKey(id);
	}

	@Override
	public Map<String, Object> selectPageResume(Resume resume) {
		Map<String, Object> map = new HashMap<>();
		int total = this.total(resume);
		map.put("pageCount", Math.ceil((double) total / resume.getPageSize()));// 总页数
		map.put("total", total);// 总条数
		map.put("index", resume.getPageIndex());// 当前页
		if (total > 0) {
			resume.setPageIndex(resume.getPageSize() * (resume.getPageIndex() - 1));
			map.put("items", resumeMapper.selectPageResume(resume));
		}
		return map;
	}

	@Override
	public int deleteResume(Resume resume) {
		return resumeMapper.deleteResume(resume);
	}

	@Override
	public int total(Resume resume) {
		return resumeMapper.total(resume);
	}
}